#!/usr/bin/env python
import difflib
import glob
import os
import datetime

string = raw_input('Enter search term: ').upper()
date = int(raw_input('Records since (date in YYYY-MM-DD): ').replace('-', ''))
pdfs = list(glob.glob('*/*.pdf'))
null = []

for index, pdf in enumerate(pdfs):
    if int(datetime.datetime.strptime(pdf.split('/')[0], '%b-%d-%Y').strftime('%Y%m%d')) < date:
        null.append(pdf)
pdfs = list(set(pdfs) ^ set(null))
results = difflib.get_close_matches(string, [pdf.split('/')[1].split('.')[0][11:] for pdf in pdfs])
pdfs = [[pdf for pdf in pdfs if result in pdf] for result in results]
if len(pdfs):
    print '\nResults:'
    for index, pdf in enumerate(pdfs):
        print index, pdf[0]
    os.system('/usr/bin/gnome-open "%s"'%pdfs[int(raw_input('\nEnter number of desired file: '))][0])
else:
    print 'No results found.'
